package cn.com.coding.system.service.impl;

import cn.com.coding.common.utils.PageUtil;
import cn.com.coding.common.utils.Query;
import cn.com.coding.system.dao.UserInfoDao;
import cn.com.coding.system.domin.UserInfoEntity;
import cn.com.coding.system.domin.dto.UserInfoDto;
import cn.com.coding.system.service.UserInfoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("userInfoService")
public class UserInfoServiceImpl extends ServiceImpl<UserInfoDao, UserInfoEntity> implements UserInfoService {

    @Override
    public PageUtil queryPage(Map<String, Object> params) {

        IPage<UserInfoDto> page = this.baseMapper.selectMyPage(new Query<UserInfoDto>().getPage(params), new QueryWrapper<UserInfoDto>().like("ui.user_name", params.get("name") != null ? params.get("name") : ""));

        return new PageUtil(page);
    }

    @Override
    public UserInfoEntity getByUserName(String username) {
        return this.baseMapper.selectOne(new QueryWrapper<UserInfoEntity>().eq("phone", username).or().eq("user_name", username));
    }

}